import axios from 'axios';
// import qs from 'qs';
import { HttpRequestOptions } from '@/types/http';

export abstract class HttpService {
  axiosGet<RequestData, ResponseData>(
    options: HttpRequestOptions<RequestData, ResponseData>
  ) {
    return new Promise<ResponseData>((resolve, reject) => {
      axios.get(options.url, {
        params: options.data,
        data: options.data,
        headers: {
          ...options.headers,
        },
      }).then((res) => {
        resolve(res.data as ResponseData);
      }).catch((err) => {
        reject(err);
      })
    });
  }

	axiosPost<RequestData, ResponseData>(
    options: HttpRequestOptions<RequestData, ResponseData>
  ) {
		return new Promise<ResponseData>((resolve, reject) => {
      axios.post(options.url, options.data, {
        headers: {
          // 'Content-Type': 'application/x-www-form-urlencoded',
          ...options.headers,
        },
        params: options.data,
      }).then((res) => {
        resolve(res.data as ResponseData);
      }).catch((err) => {
        reject(err);
      })
    });
	}
}
